// pages/home/home.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    levelFlag: false, //小程序授权弹框
    pictureUrl: '/image/',
    flag:true,
    background:'',
    newRulesFlag: false //显示更新后的代缴协议
  },
  // 查看相关协议
  rulesBtn(e){
    let index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: `../newRules/newRules?index=${index}`,
    })
  },
  onPageScroll(e){
    if(e.scrollTop > 30){
      this.setData({
        background:'#FFA418'
      })
    }else{
      this.setData({
        background:'transparent'
      })
    }
  },
  // 更多文章
  moreArticles(e) {
    let src = Number(e.currentTarget.dataset.id)
    
    wx.navigateTo({
      url: `../officialAccount/officialAccount?src=${src}`,
    })

  },
  // 跳转第三方
  outbai(){
    wx.navigateTo({
      url: '../outThird/outThird',
    })
  },
  onTabItemTap(e){
    console.log(e)
  },
  // 同意服务协议
  agreeRulesBtn(){
    this.setData({
      newRulesFlag: false
    })
    app.globalData.newRulesFlag = true
    wx.setStorageSync('newRulesFlag', true)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    setTimeout(() => {
      this.setData({
        flag: false
      })
      let flag = wx.getStorageSync('newRulesFlag')
      console.log(flag)
      if(flag == "" || flag == undefined){
        this.setData({
          newRulesFlag: true
        })
      }
    }, 300);



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(app.globalData.newRulesFlag){
      this.setData({
        newRulesFlag: false
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: "社保/公积金代缴、公积金提取!",
      path: '/pages/home/home',
      imageUrl: 'https://head.image.jiajijie.com/dj/images/fiveshareBg.png',
      success: function (res) {
      },
      fail: function (res) {
        console.log(res)
      }
    }
  }
})